.class public Lcom/facebook/orca/protocol/GetFriendsMethod;
.super Ljava/lang/Object;
.source "GetFriendsMethod.java"

# interfaces
.implements Lcom/facebook/orca/protocol/ApiMethod;


# annotations
.annotation system Ldalvik/annotation/Signature;
    value = {
        "Ljava/lang/Object;",
        "Lcom/facebook/orca/protocol/ApiMethod",
        "<",
        "Lcom/facebook/orca/server/GetFriendsParams;",
        "Lcom/facebook/orca/server/GetFriendsResult;",
        ">;"
    }
.end annotation


# instance fields
.field private final a:Lcom/facebook/orca/protocol/UserFqlHelper;

.field private final b:Lcom/facebook/orca/users/UserSerialization;


# direct methods
.method public constructor <init>(Lcom/facebook/orca/protocol/UserFqlHelper;Lcom/facebook/orca/users/UserSerialization;)V
    .locals 0
    .parameter
    .parameter
    .annotation runtime Lcom/google/inject/Inject;
    .end annotation

    .prologue
    .line 37
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 38
    iput-object p1, p0, Lcom/facebook/orca/protocol/GetFriendsMethod;->a:Lcom/facebook/orca/protocol/UserFqlHelper;

    .line 39
    iput-object p2, p0, Lcom/facebook/orca/protocol/GetFriendsMethod;->b:Lcom/facebook/orca/users/UserSerialization;

    .line 40
    return-void
.end method

.method private a(Lcom/facebook/orca/server/GetFriendsParams;Lcom/facebook/orca/protocol/FqlMultiQueryHelper;)V
    .locals 6
    .parameter
    .parameter

    .prologue
    .line 71
    invoke-direct {p0, p1}, Lcom/facebook/orca/protocol/GetFriendsMethod;->b(Lcom/facebook/orca/server/GetFriendsParams;)Landroid/util/Pair;

    move-result-object v0

    .line 72
    const-string v1, "friends"

    const-string v2, "SELECT uid2, communication_rank FROM friend WHERE uid1=me() ORDER BY communication_rank DESC LIMIT %1$d,%2$s"

    const/4 v3, 0x2

    new-array v3, v3, [Ljava/lang/Object;

    const/4 v4, 0x0

    iget-object v5, v0, Landroid/util/Pair;->first:Ljava/lang/Object;

    aput-object v5, v3, v4

    const/4 v4, 0x1

    iget-object v0, v0, Landroid/util/Pair;->second:Ljava/lang/Object;

    aput-object v0, v3, v4

    invoke-static {v2, v3}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v0

    invoke-virtual {p2, v1, v0}, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;->a(Ljava/lang/String;Ljava/lang/String;)V

    .line 78
    return-void
.end method

.method private b(Lcom/facebook/orca/server/GetFriendsParams;)Landroid/util/Pair;
    .locals 3
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Lcom/facebook/orca/server/GetFriendsParams;",
            ")",
            "Landroid/util/Pair",
            "<",
            "Ljava/lang/Integer;",
            "Ljava/lang/Integer;",
            ">;"
        }
    .end annotation

    .prologue
    .line 94
    invoke-virtual {p1}, Lcom/facebook/orca/server/GetFriendsParams;->b()Ljava/lang/String;

    move-result-object v0

    .line 97
    if-nez v0, :cond_0

    .line 98
    const/4 v0, 0x0

    .line 99
    invoke-virtual {p1}, Lcom/facebook/orca/server/GetFriendsParams;->a()I

    move-result v1

    move v2, v1

    move v1, v0

    move v0, v2

    .line 104
    :goto_0
    invoke-static {v1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v1

    invoke-static {v0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v0

    invoke-static {v1, v0}, Landroid/util/Pair;->create(Ljava/lang/Object;Ljava/lang/Object;)Landroid/util/Pair;

    move-result-object v0

    return-object v0

    .line 101
    :cond_0
    invoke-static {v0}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v0

    .line 102
    invoke-virtual {p1}, Lcom/facebook/orca/server/GetFriendsParams;->a()I

    move-result v1

    move v2, v1

    move v1, v0

    move v0, v2

    goto :goto_0
.end method

.method private b(Lcom/facebook/orca/server/GetFriendsParams;Lcom/facebook/orca/protocol/FqlMultiQueryHelper;)V
    .locals 8
    .parameter
    .parameter

    .prologue
    .line 82
    const-string v0, "friends_sync"

    const-string v1, "SELECT uid2, is_removed FROM friend_sync where uid1=me() AND update_time >= %1$d"

    const/4 v2, 0x1

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    invoke-virtual {p1}, Lcom/facebook/orca/server/GetFriendsParams;->d()J

    move-result-wide v4

    const-wide/16 v6, 0x3e8

    div-long/2addr v4, v6

    invoke-static {v4, v5}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v4

    aput-object v4, v2, v3

    invoke-static {v1, v2}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-virtual {p2, v0, v1}, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;->a(Ljava/lang/String;Ljava/lang/String;)V

    .line 87
    const-string v0, "friends"

    const-string v1, "SELECT uid2, communication_rank FROM friend WHERE uid1=me() AND uid2 IN (SELECT uid2 FROM #friends_sync)"

    invoke-virtual {p2, v0, v1}, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;->a(Ljava/lang/String;Ljava/lang/String;)V

    .line 91
    return-void
.end method


# virtual methods
.method public a(Lcom/facebook/orca/server/GetFriendsParams;)Lcom/facebook/orca/protocol/ApiRequest;
    .locals 5
    .parameter

    .prologue
    .line 44
    invoke-static {}, Lcom/google/common/collect/Lists;->a()Ljava/util/ArrayList;

    move-result-object v0

    .line 45
    new-instance v1, Lorg/apache/http/message/BasicNameValuePair;

    const-string v2, "format"

    const-string v3, "json"

    invoke-direct {v1, v2, v3}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 47
    new-instance v1, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;

    invoke-direct {v1}, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;-><init>()V

    .line 48
    invoke-virtual {p1}, Lcom/facebook/orca/server/GetFriendsParams;->c()Z

    move-result v2

    if-eqz v2, :cond_0

    .line 50
    invoke-direct {p0, p1, v1}, Lcom/facebook/orca/protocol/GetFriendsMethod;->b(Lcom/facebook/orca/server/GetFriendsParams;Lcom/facebook/orca/protocol/FqlMultiQueryHelper;)V

    .line 55
    :goto_0
    const-string v2, "users"

    const-string v3, "SELECT uid, first_name, last_name, name, contact_email, phones, is_pushable FROM user WHERE uid IN (SELECT uid2 FROM #friends)"

    invoke-virtual {v1, v2, v3}, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;->a(Ljava/lang/String;Ljava/lang/String;)V

    .line 60
    const-string v2, "profiles"

    const-string v3, "SELECT id, name, type, pic_big, pic_square, pic_crop FROM profile WHERE id IN (SELECT uid2 FROM #friends)"

    invoke-virtual {v1, v2, v3}, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;->a(Ljava/lang/String;Ljava/lang/String;)V

    .line 65
    new-instance v2, Lorg/apache/http/message/BasicNameValuePair;

    const-string v3, "queries"

    invoke-virtual {v1}, Lcom/facebook/orca/protocol/FqlMultiQueryHelper;->a()Lorg/json/JSONObject;

    move-result-object v1

    invoke-virtual {v1}, Lorg/json/JSONObject;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-direct {v2, v3, v1}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {v0, v2}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 66
    new-instance v1, Lcom/facebook/orca/protocol/ApiRequest;

    const-string v2, "getFriends"

    const-string v3, "GET"

    const-string v4, "method/fql.multiquery"

    invoke-direct {v1, v2, v3, v4, v0}, Lcom/facebook/orca/protocol/ApiRequest;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)V

    return-object v1

    .line 53
    :cond_0
    invoke-direct {p0, p1, v1}, Lcom/facebook/orca/protocol/GetFriendsMethod;->a(Lcom/facebook/orca/server/GetFriendsParams;Lcom/facebook/orca/protocol/FqlMultiQueryHelper;)V

    goto :goto_0
.end method

.method public bridge synthetic a(Ljava/lang/Object;)Lcom/facebook/orca/protocol/ApiRequest;
    .locals 1
    .parameter

    .prologue
    .line 27
    check-cast p1, Lcom/facebook/orca/server/GetFriendsParams;

    invoke-virtual {p0, p1}, Lcom/facebook/orca/protocol/GetFriendsMethod;->a(Lcom/facebook/orca/server/GetFriendsParams;)Lcom/facebook/orca/protocol/ApiRequest;

    move-result-object v0

    return-object v0
.end method

.method public a(Lcom/facebook/orca/server/GetFriendsParams;Lcom/facebook/orca/protocol/ApiResponse;)Lcom/facebook/orca/server/GetFriendsResult;
    .locals 8
    .parameter
    .parameter

    .prologue
    .line 110
    invoke-static {p2}, Lcom/facebook/orca/protocol/ApiResponseWrapper;->a(Lcom/facebook/orca/protocol/ApiResponse;)Lcom/facebook/orca/protocol/ApiResponseWrapper;

    move-result-object v0

    .line 111
    invoke-virtual {v0}, Lcom/facebook/orca/protocol/ApiResponseWrapper;->b()Lorg/json/JSONArray;

    move-result-object v0

    .line 112
    new-instance v1, Lcom/facebook/orca/protocol/FqlResultHelper;

    invoke-direct {v1, v0}, Lcom/facebook/orca/protocol/FqlResultHelper;-><init>(Lorg/json/JSONArray;)V

    .line 114
    const-string v0, "friends"

    invoke-virtual {v1, v0}, Lcom/facebook/orca/protocol/FqlResultHelper;->a(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object v0

    .line 115
    const-string v2, "users"

    invoke-virtual {v1, v2}, Lcom/facebook/orca/protocol/FqlResultHelper;->a(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object v2

    .line 116
    const-string v3, "profiles"

    invoke-virtual {v1, v3}, Lcom/facebook/orca/protocol/FqlResultHelper;->a(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object v3

    .line 117
    if-eqz v2, :cond_0

    if-eqz v3, :cond_0

    if-nez v0, :cond_1

    .line 118
    :cond_0
    new-instance v0, Ljava/lang/Exception;

    const-string v1, "Invalid api response - missing friends"

    invoke-direct {v0, v1}, Ljava/lang/Exception;-><init>(Ljava/lang/String;)V

    throw v0

    .line 120
    :cond_1
    iget-object v4, p0, Lcom/facebook/orca/protocol/GetFriendsMethod;->a:Lcom/facebook/orca/protocol/UserFqlHelper;

    invoke-virtual {v4, v2, v3, v0}, Lcom/facebook/orca/protocol/UserFqlHelper;->a(Lorg/json/JSONArray;Lorg/json/JSONArray;Lorg/json/JSONArray;)Lorg/json/JSONArray;

    move-result-object v2

    .line 123
    iget-object v3, p0, Lcom/facebook/orca/protocol/GetFriendsMethod;->b:Lcom/facebook/orca/users/UserSerialization;

    sget-object v4, Lcom/facebook/orca/users/User$Type;->FACEBOOK:Lcom/facebook/orca/users/User$Type;

    invoke-virtual {v3, v4, v2}, Lcom/facebook/orca/users/UserSerialization;->a(Lcom/facebook/orca/users/User$Type;Lorg/json/JSONArray;)Lcom/google/common/collect/ImmutableList;

    move-result-object v2

    .line 126
    const/4 v3, 0x0

    .line 127
    invoke-virtual {p1}, Lcom/facebook/orca/server/GetFriendsParams;->c()Z

    move-result v4

    if-eqz v4, :cond_4

    .line 128
    invoke-static {}, Lcom/google/common/collect/ImmutableList;->h()Lcom/google/common/collect/ImmutableList$Builder;

    move-result-object v0

    .line 129
    const-string v4, "friends_sync"

    invoke-virtual {v1, v4}, Lcom/facebook/orca/protocol/FqlResultHelper;->a(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object v1

    .line 130
    const/4 v4, 0x0

    :goto_0
    invoke-virtual {v1}, Lorg/json/JSONArray;->length()I

    move-result v5

    if-ge v4, v5, :cond_3

    .line 131
    invoke-virtual {v1, v4}, Lorg/json/JSONArray;->getJSONObject(I)Lorg/json/JSONObject;

    move-result-object v5

    .line 132
    const-string v6, "is_removed"

    invoke-virtual {v5, v6}, Lorg/json/JSONObject;->getBoolean(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_2

    .line 133
    const-string v6, "uid2"

    invoke-virtual {v5, v6}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v5

    invoke-static {v5}, Lcom/facebook/orca/common/util/JSONUtil;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v0, v5}, Lcom/google/common/collect/ImmutableList$Builder;->a(Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList$Builder;

    .line 130
    :cond_2
    add-int/lit8 v4, v4, 0x1

    goto :goto_0

    .line 136
    :cond_3
    invoke-virtual {v0}, Lcom/google/common/collect/ImmutableList$Builder;->a()Lcom/google/common/collect/ImmutableList;

    move-result-object v0

    move-object v5, v3

    move-object v4, v0

    .line 145
    :goto_1
    new-instance v0, Lcom/facebook/orca/server/GetFriendsResult;

    sget-object v1, Lcom/facebook/orca/server/DataFreshnessResult;->FROM_SERVER:Lcom/facebook/orca/server/DataFreshnessResult;

    invoke-virtual {p1}, Lcom/facebook/orca/server/GetFriendsParams;->c()Z

    move-result v3

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v6

    invoke-direct/range {v0 .. v7}, Lcom/facebook/orca/server/GetFriendsResult;-><init>(Lcom/facebook/orca/server/DataFreshnessResult;Lcom/google/common/collect/ImmutableList;ZLcom/google/common/collect/ImmutableList;Ljava/lang/String;J)V

    return-object v0

    .line 138
    :cond_4
    invoke-virtual {v0}, Lorg/json/JSONArray;->length()I

    move-result v0

    if-eqz v0, :cond_5

    .line 139
    invoke-direct {p0, p1}, Lcom/facebook/orca/protocol/GetFriendsMethod;->b(Lcom/facebook/orca/server/GetFriendsParams;)Landroid/util/Pair;

    move-result-object v0

    .line 140
    iget-object p0, v0, Landroid/util/Pair;->first:Ljava/lang/Object;

    check-cast p0, Ljava/lang/Integer;

    invoke-virtual {p0}, Ljava/lang/Integer;->intValue()I

    move-result v1

    iget-object p0, v0, Landroid/util/Pair;->second:Ljava/lang/Object;

    check-cast p0, Ljava/lang/Integer;

    invoke-virtual {p0}, Ljava/lang/Integer;->intValue()I

    move-result v0

    add-int/2addr v0, v1

    invoke-static {v0}, Ljava/lang/Integer;->toString(I)Ljava/lang/String;

    move-result-object v0

    .line 142
    :goto_2
    invoke-static {}, Lcom/google/common/collect/ImmutableList;->g()Lcom/google/common/collect/ImmutableList;

    move-result-object v1

    move-object v5, v0

    move-object v4, v1

    goto :goto_1

    :cond_5
    move-object v0, v3

    goto :goto_2
.end method

.method public bridge synthetic a(Ljava/lang/Object;Lcom/facebook/orca/protocol/ApiResponse;)Ljava/lang/Object;
    .locals 1
    .parameter
    .parameter

    .prologue
    .line 27
    check-cast p1, Lcom/facebook/orca/server/GetFriendsParams;

    invoke-virtual {p0, p1, p2}, Lcom/facebook/orca/protocol/GetFriendsMethod;->a(Lcom/facebook/orca/server/GetFriendsParams;Lcom/facebook/orca/protocol/ApiResponse;)Lcom/facebook/orca/server/GetFriendsResult;

    move-result-object v0

    return-object v0
.end method
